package com.ynunicom.dc.dingdingcontractapp.controller;

import com.alibaba.fastjson.JSONObject;
import com.ynunicom.dc.dingdingcontractapp.dto.ResponseDto;
import com.ynunicom.dc.dingdingcontractapp.entity.StandReturnerImpl;
import com.ynunicom.dc.dingdingcontractapp.entity.requestbodyentity.*;
import com.ynunicom.dc.dingdingcontractapp.service.RoleService;
import lombok.SneakyThrows;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: jinye.Bai
 * @date: 2020/6/2 17:56
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    RoleService roleService;

    @SneakyThrows
    @PostMapping("/createGroup")
    public ResponseDto<JSONObject> createGroup(@RequestBody  @Validated CreateGroupRequestBody createGroupRequestBody, @RequestParam("access_token") String access_token){
        TransBody<CreateGroupRequestBody> transBody = new TransBody<>(createGroupRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("createRoleGroup",TransBody.class));
    }


    @SneakyThrows
    @PostMapping("/createRole")
    public ResponseDto<JSONObject> createRole(@RequestBody @Validated CreateRoleRequestBody roleRequestBody,@RequestParam("access_token") String access_token){
        TransBody<CreateRoleRequestBody> transBody = new TransBody<>(roleRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("createRole",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/getRoleGroup")
    public ResponseDto<JSONObject> getRoleGroup(@RequestBody @Validated GetRoleGroupRequestBody getRoleGroupRequestBody,@RequestParam("access_token") String access_token){
        TransBody<GetRoleGroupRequestBody> transBody = new TransBody<>(getRoleGroupRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("getRoleGroup",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/getRoleInfo")
    public ResponseDto<JSONObject> getRoleInfo(@RequestBody @Validated DelRoleOrGetRoleInfoRequestBody delRoleOrGetRoleInfoRequestBody,@RequestParam("access_token") String access_token){
        TransBody<DelRoleOrGetRoleInfoRequestBody> transBody = new TransBody<>(delRoleOrGetRoleInfoRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("getRoleInfo",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/getRoleList")
    public ResponseDto<JSONObject> getRoleList(@RequestBody @Validated GetRoleListRequestBody getRoleListRequestBody,@RequestParam("access_token") String access_token){
        TransBody<GetRoleListRequestBody> transBody = new TransBody<>(getRoleListRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("getRoleList",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/getStaffListByRole")
    public ResponseDto<JSONObject> getStaffListByRole(@RequestBody @Validated GetStaffListByRoleRequestBody getStaffListByRoleRequestBody,@RequestParam("access_token") String access_token){
        TransBody<GetStaffListByRoleRequestBody> transBody = new TransBody<>(getStaffListByRoleRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("getStaffListByRole",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/updateRole")
    public ResponseDto<JSONObject> updateRole(@RequestBody @Validated UpdateRoleRequestBody updateRoleRequestBody,@RequestParam("access_token") String access_token){
        TransBody<UpdateRoleRequestBody> transBody = new TransBody<>(updateRoleRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("updateRole",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/delRole")
    public ResponseDto<JSONObject> delRole(@RequestBody @Validated DelRoleOrGetRoleInfoRequestBody delRoleOrGetRoleInfoRequestBody,@RequestParam("access_token") String access_token){
        TransBody<DelRoleOrGetRoleInfoRequestBody> transBody = new TransBody<>(delRoleOrGetRoleInfoRequestBody,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("delRole",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/addRolesForStaffs")
    public ResponseDto<JSONObject> addRolesForStaffs(@RequestBody @Validated DelOrAddRolesForStaffs delOrAddRolesForStaffs,@RequestParam("access_token") String access_token){
        TransBody<DelOrAddRolesForStaffs> transBody = new TransBody<>(delOrAddRolesForStaffs,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("addRolesForStaffs",TransBody.class));
    }

    @SneakyThrows
    @PostMapping("/delRoleForStaffs")
    public ResponseDto<JSONObject> delRoleForStaffs(@RequestBody @Validated DelOrAddRolesForStaffs delOrAddRolesForStaffs,@RequestParam("access_token") String access_token){
        TransBody<DelOrAddRolesForStaffs> transBody = new TransBody<>(delOrAddRolesForStaffs,access_token);
        return new StandReturnerImpl().doReturn(transBody,roleService.getClass(),roleService.getClass().getMethod("delRoleForStaffs",TransBody.class));
    }
}
